from django.contrib import admin
from models import Category, Post, Artist, ArtistPosition


class ArtistPositionInline(admin.TabularInline):
    model = ArtistPosition
    extra = 2

class ArtistAdmin(admin.ModelAdmin):
    list_display = ('name', 'image')
    list_editable = ('image',)
    model = Artist

class PostAdmin(admin.ModelAdmin):
    model = Post
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('title', 'category', 'date', 'text')}
        ),
    )
    def get_form(self, request, obj=None, **kwargs):
        """
        Use special form during user creation
        """
        defaults = {}
        if obj is None:
            defaults.update({
                
                'fields': admin.util.flatten_fieldsets(self.add_fieldsets),
            })
        defaults.update(kwargs)
        return super(PostAdmin, self).get_form(request, obj, **defaults)

admin.site.register(Category)
admin.site.register(Post, PostAdmin)
admin.site.register(ArtistPosition)
admin.site.register(Artist, ArtistAdmin)